<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@include file="../../common/common-head.jsp"%>

<body>

    <!-- begin #content -->
    <div id="content" class="content">
        <c:set var="listName" value="站点设置" />
        <%@include file="../../common/common-breadcrumb.jsp"%>

        <!-- begin row -->
        <div class="row">
            <!-- begin col-6 -->
            <div class="col-xl-6">
                <!-- begin panel -->
                <div class="panel panel-inverse" data-sortable-id="form-stuff-11">
                    <c:set var="panelName" value="设置站点信息" />
                    <%@include file="../../common/common-panel-heading.jsp"%>

                    <!-- begin panel-body -->
                    <div class="panel-body">
                        <form action="/" method="POST">
                            <input type="hidden" id="id" value="${obj.id}">
                            <input type="hidden" id="websiteLogo" value="${obj.websiteLogo}" >

                            <fieldset>
                                <div class="form-group row m-b-15">
                                    <label class="col-md-3 col-form-label">站点名称</label>
                                    <div class="col-md-7">
                                        <input type="text" class="form-control" placeholder="站点名称" id="websiteName" value="${obj.websiteName}" />
                                    </div>
                                </div>
                                <div class="form-group row m-b-15">
                                    <label class="col-md-3 col-form-label">poweredBy信息</label>
                                    <div class="col-md-7">
                                        <input type="text" class="form-control" placeholder="poweredBy" id="poweredBy" value="${obj.poweredBy}" />
                                    </div>
                                </div>
                                <div class="form-group row m-b-15">
                                    <label class="col-md-3 col-form-label">公司名称</label>
                                    <div class="col-md-7">
                                        <input type="text" class="form-control" placeholder="公司名称" id="companyName" value="${obj.companyName}" />
                                    </div>
                                </div>
                                <div class="form-group row m-b-15">
                                    <label class="col-md-3 col-form-label">网站标题</label>
                                    <div class="col-md-7">
                                        <input type="text" class="form-control" placeholder="网站标题" id="websiteTitle" value="${obj.websiteTitle}"/>
                                    </div>
                                </div>
                                <div class="form-group row m-b-15">
                                    <label class="col-md-3 col-form-label">网站Logo</label>
                                    <img src="${cdnServer}${obj.logo}" id="logoId" onclick="openPhoto()" width="114px">
                                    <input type="file" name="file" id="file" style="display: none" onchange="uploadFile()">
                                </div>

                                <div class="form-group row">
                                    <div class="col-md-7 offset-md-3">
                                        <button type="button" class="btn btn-sm btn-primary m-r-5" id="saveObj">保存</button>
                                    </div>
                                </div>
                            </fieldset>
                        </form>
                    </div>
                    <!-- end panel-body -->
                </div>
                <!-- end panel -->
            </div>
            <!-- end col-6 -->
        </div>
        <!-- end row -->
    </div>
    <!-- end #content -->

</body>

<%@include file="../../common/common-script.jsp"%>

<script>
    var ctx = "${basePath}"
    var cdnServer = "${cdnServer}"

    function openPhoto(){
        $("#file").trigger("click")
    }

    function uploadFile(p){
        var formData=new FormData();
        formData.append("file",$('#file').prop('files')[0]);
        $.ajax({
            type:'POST',
            url:'/ServletUpload',
            data:formData,
            contentType: false,// 注意：让jQuery不要处理数据
            processData: false,// 注意：让jQuery不要设置contentType
            dataType:'json',
            success:function (res) {
                $("#logoId").attr("src",cdnServer+res.path)
                $("#websiteLogo").attr("value",res.id)
            }
        });
    }

    $(function(){
        $('#saveObj').click(function(){

            var website = {}
            website['id'] = $('#id').val()
            website['websiteName'] = $('#websiteName').val()
            website['poweredBy'] = $('#poweredBy').val()
            website['companyName'] = $('#companyName').val()
            website['websiteTitle'] = $('#websiteTitle').val()
            website['websiteLogo'] = $('#websiteLogo').val()

            $.ajax({
                type:'post',
                url:ctx+'dashboard/website/settings',
                data:JSON.stringify(website),
                success:function (res){
                    if(res=="1000"){
                        swal({
                            title: '成功',
                            text: '网站信息保存成功!',
                            icon: 'info',
                            buttons: {
                                cancel: {
                                    text: 'Cancel',
                                    value: null,
                                    visible: true,
                                    className: 'btn btn-default',
                                    closeModal: true,
                                },
                                confirm: {
                                    text: 'Primary',
                                    value: true,
                                    visible: true,
                                    className: 'btn btn-primary',
                                    closeModal: true
                                }
                            }
                        });
                    }
                }
            })

        })
    })

</script>

</html>
